#include <iostream>
#include <fstream>

using namespace std;

int main(int argc, char **argv)
{
  if (argc != 5){cout<<"\nUsage: "<<argv[0]<<" solnfile evecfile coeff outfile\n\n";exit(1);}
  
  ifstream fsol(argv[1]); if(fsol.fail()){cout<<"bad infile: "<<argv[1]<<endl;exit(1);}
  ifstream fvec(argv[2]); if(fvec.fail()){cout<<"bad infile: "<<argv[2]<<endl;exit(1);}
  
  int m, n;
  double p0, Q, A, B, P1, P2, A1, A2, A3;
  char type[32];

  fsol >> type >> m >> n >> p0 >> Q;
  
  if (strcmp(type, "exp")==0)
    fsol >> A >> B;
  else if (strcmp(type, "step")==0)
    fsol >> P1 >> P2 >> A1 >> A2 >> A3;
  else { cerr << "error: unknown vorticity function type: " << type << "; known types are \"exp\" and \"step\"" << endl; exit(1); }
  
  int dim = m*n;
  double z[dim];
  double c = atof(argv[3]);

  double x, y;
  for (int i=0; i<dim; ++i)
  {
    fsol >> x;
    fvec >> y;
    z[i] = x + c*y;
  }

  fsol.close();
  fvec.close();

  ofstream fz(argv[4], ios::trunc);
  fz.precision(15);

  fz << type << endl
     << m << endl
     << n << endl
     << p0 << endl
     << Q << endl;
  if (strcmp(type, "exp")==0)
    fz << A << endl
       << B << endl << endl;
  else if (strcmp(type, "step")==0)
    fz << P1 << endl
       << P2 << endl
       << A1 << endl
       << A2 << endl
       << A3 << endl << endl;
  
  for (int i=0; i<dim; ++i)
    fz << z[i] << endl;
  fz.close();
}
